<template>
	<view class="pages">
		<uni-list :border="false" style="height:auto">
			<zgj-channel :list="list"></zgj-channel>
		</uni-list>
	</view>
</template>

<script>
	import {
		store
	} from '@/uni_modules/uni-id-pages/common/store.js'
	import {
		favMapper
	} from '@/uni_modules/zgj-pages/common/favorite.js'
	export default {
		data() {
			return {
				list: []
			}
		},
		computed: {
			userInfo() {
				return store.userInfo
			},
			isSigned() {
				return this.userInfo && !!this.userInfo._id
			}
		},
		async onLoad() {
			if(this.isSigned){
				this.loadData(this.userInfo._id)
			}
		},
		methods: {
			async loadData(id){
				let rcrd =await favMapper.getFavorites(this.userInfo._id)
				console.log('favs:',rcrd)
				let ids = rcrd === null ? [] : rcrd.channel_ids
				if(ids.length>0){
					this.$http.post('/web/ai/channels', {channel_ids:ids}, (resp) => {
						resp.forEach((v) => {
							var phones = v.contact_phone || ''
							phones = phones.split(',')
							v.phones = phones.concat(v.tel)
							v.tags.forEach((t) => {
								if (t.tag_id === 100) {
									v.dprz = true
								} else if (t.tag_id === 101) {
									v.bzj = true
								} else if (t.tag_id === 125) {
									v.pps = true
								}
							})
						})
						this.list = resp
					})
				}
			}
		}
	}
</script>

<style>
	.item {
		display: flex;
		flex-direction: column;
	}

	.article-date {
		color: #C8C7CC;
	}
</style>